package com.maozzi.web.configuration;

import com.maozzi.api.auth.AuthInterceptor;
import com.maozzi.api.auth.LoginInterceptor;
import com.maozzi.api.auth.properties.AuthProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 拦截器配置
 *
 * @author maozi
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Resource
    private AuthProperties authProperties;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 登录拦截
        LoginInterceptor loginInterceptor = new LoginInterceptor(authProperties);
        registry.addInterceptor(loginInterceptor)
                .excludePathPatterns("/rest/admin/login.json")
        ;
        // 权限拦截
        AuthInterceptor authInterceptor = new AuthInterceptor(authProperties);
        registry.addInterceptor(authInterceptor)
                .excludePathPatterns("/rest/admin/login.json")
        ;
    }
}
